package com.oracle.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.oracle.common.TemplateMoudleMethod;
import com.oracle.moudle.TemplateMoudleimp;
import com.oracle.service.FeignGetBoyService;
import com.oracle.service.IBoyService;
import com.oracle.vo.Boy;
import com.oracle.vo.Girl;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;



import java.util.*;


/**
 * @program: CampusMatching
 * @description:
 * @author: zhaolei
 * @create: 2020-07-24 16:07
 **/
@Controller
@RequestMapping("/Boy")
public class SourceHandler implements FeignGetBoyService  {

    @Autowired
    IBoyService iBoyService;

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    DiscoveryClient discoveryClient;




    @GetMapping("/index")
    public String getPage(){
        System.out.println("进入男士入口");
        return "Main";
    }



    @PostMapping("/getGirl")
    public String getgirl(Boy boy, Map<String,Object> map){
        map.put("boy",boy);
        System.out.println("映射成功！");
     
        System.out.println(boy.toString());
//        "http://girlmatching/Girl/getGirl?boy={boy}",Girl.class,boy
       List <Girl>list =restTemplate.postForObject("http://girlmatching/Girl/getGirl",boy,List.class);
//        System.out.println(girl.toString());
//       map.put("resgirl",girl);
//        System.out.println("得到map："+map1);
//        System.out.println("得到list2："+map1.get("girllist"));


        map.put("rgirl", list);
        return "resgirl";
    }

    //被调用的服务
    @Override
    @HystrixCommand
    @PostMapping("/getboy")
    @ResponseBody
    public List getBoy(Girl girl){
        System.out.println("映射成功！");
        System.out.println(girl.toString());
        TemplateMoudleMethod templateMoudleMethod=new TemplateMoudleimp(girl);
        List<Object> list=templateMoudleMethod.run();
        System.out.println(list);
        return list;
    }





}
